package com.lxy.testsurfaceview;

import java.io.InputStream;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.text.style.BulletSpan;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {
	private ImageView im;
	private Button bu;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		bu=(Button) findViewById(R.id.bu);
		im=(ImageView) findViewById(R.id.im);
		
		bu.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent=new Intent(MainActivity.this,CameraActivity.class);
				
				startActivityForResult(intent, 1);
			}
		});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(resultCode==2){
			Log.i("resultCode","result"+resultCode);
			Bundle b=data.getBundleExtra("photo");
			byte[] d=b.getByteArray("photo");
			Bitmap bm=BitmapFactory.decodeByteArray(d, 0, d.length);
			Matrix matrix = new Matrix();  
			matrix.postRotate(90);  
		   bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(),  
		                matrix, true);  
			im.setImageBitmap(bm);
		}
	}

	
}
